#region MIT Licence
/*
 * Copyright (C) 2014 PdfCreative
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software 
 * and associated documentation files (the "Software"), to deal in the Software without restriction, 
 * including without limitation the rights to use, copy, modify, merge, publish, distribute, 
 * sublicense, and/or sell copies of the Software, and to permit persons to whom 
 * the Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included 
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 
 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE 
 * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
#endregion

using System;
using System.Collections.Generic;
using System.Text;

using PdfCreative.Pdf.Writer;

namespace PdfCreative.Pdf.Graphics
{
    /// <summary>
    /// The SolidBrush class represents a brush that fills areas with a solid colour. It inherits from the
    /// abstract Brush class. This brush does not require a resource.
    /// </summary>
    public class SolidBrush : Brush
    {
        // Private fields
        // ==============
        #region Private fields
        private Colour _colour;
        #endregion



        // Public properties
        // =================
        #region Public properties
        /// <summary>
        /// Sets or retrieves the colour of this solid brush.
        /// </summary>
        public Colour Colour
        {
            get { return _colour; }
            set
            {
                if (null == value)
                    throw new ArgumentNullException("value");

                _colour = value; 
            }
        }
        #endregion



        // Base class overrides
        // ====================
        #region Object overrides
        /// <summary>
        /// Indicates if this brush is equal to a specified other instance.
        /// </summary>
        /// <param name="obj">The other instance to compare this pen with</param>
        /// <returns>A boolean indicating that the two instances are equal (true) or not</returns>
        public override bool Equals(object obj)
        {
            SolidBrush otherBrush = obj as SolidBrush;
            return
                null != otherBrush &&
                otherBrush._colour.Equals(_colour);
        }

        /// <summary>
        /// Retrieves the hash code for the brush.
        /// </summary>
        /// <returns>The brush's hash code</returns>
        public override int GetHashCode()
        {
            return _colour.GetHashCode();
        }
        #endregion

        #region Brush overrides
        /// <summary>
        /// Clones this brush instance.
        /// </summary>
        /// <returns>The clone</returns>
        public override Brush Clone()
        {
            return new SolidBrush(_colour.Clone());
        }

        /// <summary>
        /// Indicates if the brush requires a resource.
        /// </summary>
        protected internal override bool RequiresResource
        {
            get { return false; }
        }
        /// <summary>
        /// Writes the changes between this brush and the specified other brush.
        /// </summary>
        /// <param name="writer">The Writer to write to</param>
        /// <param name="otherBrush">The other brush</param>
        protected internal override void WriteChanges(PdfWriter writer, Brush otherBrush)
        {
            // We set the current filling colour to the colour of this solid brush.
            _colour.WriteNonStrokeColour(writer);
        }
        #endregion



        // Public constructor
        // ==================
        #region Public constructor
        /// <summary>
        /// Constructs a new PdfSolidBrush instance with the specified colour.
        /// </summary>
        /// <param name="colour">The colour</param>
        public SolidBrush(Colour colour)
        {
            if (null == colour)
                throw new ArgumentNullException("colour");

            this.Colour = colour;
        }
        #endregion

    } // PdfSolidBrush class
}
